<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言管理</title>
<link href="<%=request.getContextPath() %>/css/Style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.3.2.js"></script>
<script type="text/javascript">
	function checkAll(obj) {
		var news = document.getElementsByName("msgs");
		if (obj.checked) {
			for ( var i = 0; i < news.length; i++) {
				news[i].checked = true;
			}
		}else{
			for ( var i = 0; i < news.length; i++) {
				news[i].checked = false;
			}
		}
	}
	function promptDialog(callback, args) {
		if (confirm("是否執行該操作?")) {
			if (args != null) {
				callback(args);
			} else {
				callback();
			}
		}
	}
	
	function deleteItem() {
		var news = document.getElementsByName("msgs");
		var deleteItem = "";
		for ( var i = 0; i < news.length; i++) {
			if(news[i].checked){
				deleteItem+=news[i].value+",";
			}
		}
		if(deleteItem==""){
				alert("至少选择一个才能进行操作！");
				return false;
			}
		var path='<%=request.getContextPath()%>';
		deleteItem = deleteItem.substring(0,deleteItem.length-1);
		var href= window.location.href;
		$.ajax({
			type: "GET",
            url: path + "/admin/deleteMsg.htm",
            data:{
				mid:deleteItem
            },
            dataType: "text",
            success: function(result){
            	 if(result=="success"){
                 	 alert("操作成功！");
                	 window.location.href=href;
                 }else{
              	   alert("操作失败！");
                     }
            },
            error: function(){
              alert("数据库繁忙，请稍后再试！");
            }
		});
	}
	function goPage(page){
			document.getElementById("currentPage").value=page;
			document.getElementById("n_form").submit();
		}
</script>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" class="thead" width="100%">
	<tr><td style="padding:3px;">当前位置:留言管理</td></tr>
</table>
<form action="<%=request.getContextPath() %>/admin/getMsg.htm" method="post" id="n_form">
<table cellspacing="0" cellpadding="0" bordercolor="#003366" border="1" width="100%" class="Table1">
	<tbody>
		<tr height="30px">
			<td colspan="6" >
				<span class="top_c"><input type="button" value="删除" onclick="promptDialog(deleteItem,null)" class="btn"/></span>
			</td>
		</tr>
		<tr>
			<td height="25" align="center"><input type="checkbox" onclick="checkAll(this)" /></td>
			<td height="25" align="center">留言信息</td>
			<td height="25" align="center">留言作者</td>
			<td height="25" align="center">留言IP</td>
			<td height="25" align="center">留言时间</td>
		</tr>
		<s:iterator value="message.datas" id="item" status="index">
		<tr>
			<td height="25" align="center"><input type="checkbox" name="msgs" value="<s:property value="#item.id"/>"/></td>
			<td height="25" align="left"><s:property value="#item.content"/></td>
			<td height="25" align="center"><s:property value="#item.auther"/></td>
			<td height="25" align="center"><s:property value="#item.ip"/></td>
			<td height="25" align="center"><s:date name="#item.msgDate" nice="false" format="yyyy-MM-dd HH:mm:ss"/></td>
		</tr>
		</s:iterator>
		<tr>
			<td colspan="6" height="30px" align="right">
			<span style="padding-right:10px">[第<b>${message.currentPage}</b>页|共<b>${message.pageCount}</b>页]
					<s:if test="message.currentPage<2"><span class="disable" >&lt;&lt;上一页</span></s:if><s:else><a class="enable" href="javascript:goPage(${message.currentPage}-1)">&lt;&lt;上一页</a></s:else>
					<s:if test="message.currentPage>=message.pageCount"><span class="disable">下一页&gt;&gt;</span></s:if><s:else><a class="enable" href="javascript:goPage(${message.currentPage+1})">下一页&gt;&gt;</a></s:else>
			</span>
			</td>
		</tr>
	</tbody>
</table>
	<input type="hidden" value="" name="currentPage" id="currentPage" />
	<input type="hidden" value="${nodeid}" name="nodeid">
</form>
</body>
</html>